<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class table_common_member_openid extends discuz_table_archive
{
	private $_fields;

	public function __construct() {
		$this->_table = 'common_member_profile';
		$this->_pk    = 'uid';
		$this->_pre_cache_key = 'common_member_profile_';
		$this->_fields = array('uid', 'realname', 'gender', 'birthyear', 'birthmonth', 'birthday', 'constellation',
				'zodiac', 'telephone', 'mobile', 'idcardtype', 'idcard', 'address', 'zipcode', 'nationality', 'birthprovince', 'birthcity', 'birthdist',
				'birthcommunity', 'resideprovince', 'residecity', 'residedist', 'residecommunity', 'residesuite', 'graduateschool', 'education', 'company',
				'occupation', 'position', 'revenue', 'affectivestatus', 'lookingfor', 'bloodtype', 'height', 'weight', 'alipay', 'icq', 'qq',
				'yahoo', 'msn', 'taobao', 'site', 'bio', 'interest', 'field1', 'field2', 'field3', 'field4', 'field5', 'field6', 'field7', 'field8');

		parent::__construct();
	}

	public function fetch_openid($openid) {
        $query = DB::query('SELECT uid, site as openid, height as fid, weight as tid, icq as headURL, gender as gender, address as address FROM '.DB::table($this->_table).' WHERE site = \'' . $openid . "'");
        while($value = DB::fetch($query)) {
            return $value;
        }
        return NULL;
    }
    
    public function fetch_by_uid($uid) {
    	$query = DB::query('SELECT uid, site as openid, height as fid, weight as tid, icq as headURL, gender as gender, address as address FROM '.DB::table($this->_table).' WHERE uid = \'' . $uid . "'");
    	while($value = DB::fetch($query)) {
    		return $value;
    	}
    	return NULL;
    }
    
    public function fetch_user_by_tid($tid) {
    	$query = DB::query('SELECT uid, site as openid, height as fid, weight as tid, icq as headURL, gender as gender, address as address FROM '.DB::table($this->_table).' WHERE weight = \'' . $tid . "'");
    	$users = array();
    	while($value = DB::fetch($query)) {
    		array_push($users, $value);
    	}
    	return $users;
    }
    
    public function update_tid_by_uid($uid, $tid) {
    	$query = DB::query('Update '.DB::table($this->_table)." set weight='" .$tid . "' WHERE uid = '" . $uid . "'");
    	 
    }
    
    public function update_fid_by_uid($uid, $fid) {
    	$query = DB::query('Update '.DB::table($this->_table)." set height='" .$fid . "' WHERE uid = '" . $uid . "'");
    }
}

?>
